<!--
 * @FileDescription 车窗系统
 * @Author lz
 * @Date 20230801 13:54:13
 * @LastEditors lz
 * @LastEditTime 20230801 13:54:13
-->
<template>
    <div class="ws_wp">
        <Hdr></Hdr>
        <img src="/images/Benz600/ic_back.png" class="return_ico" @click="ret">
        <div class="ActionBar">
            <div class="fb_l" @click="VLQR"></div>
            <div class="fb_r" @click="OPQR"></div>

            <div class="upArrow" @mousedown="ArrowClick" @mouseup="ArrowRelease"> </div>
            <div class="downArrow" @mousedown="DowArrowClick" @mouseup="DowArrowRelease">
            </div>
            <div class="upArrow2" @click="OpenDirectly"></div>
            <div class="downArrow2" @click="DirectlyClose"></div>

            <div class="locw" :class="state.current == 1 ? 'locwSele' : ''" @click="SelectModule(1)">
                左前车窗
            </div>
            <div class="locw L2" :class="state.current == 2 ? 'locwSele' : ''" @click="SelectModule(2)">
                左后车窗
            </div>
            <!-- <div class="locw L3" :class="state.current == 3 ? 'locwSele' : ''" @click="SelectModule(3)">
                天窗
            </div> -->
            <div class="locw L4" :class="state.current == 4 ? 'locwSele' : ''" @click="SelectModule(4)">
                右前车窗
            </div>
            <div class="locw L5" :class="state.current == 5 ? 'locwSele' : ''" @click="SelectModule(5)">
                右后车窗
            </div>
        </div>
        <VideoList v-if="HomeContent.Default.VideoList.value"></VideoList>
    </div>
    <QRCodeMask v-if="HomeContent.Default.QRType.value"></QRCodeMask>
</template>

<script setup lang="ts">
import Hdr from '../Head/index.vue'
import { useRouter } from 'vue-router'
import QRCodeMask from '../QRCodeMask/index.vue'
import VideoList from '../VideoList/index.vue'
import { onMounted, ref, nextTick, reactive } from 'vue';
import { ClientMessage } from '@runtime/generate/message/ClientMessage';
import WebSocketComponent from '@runtime/module/WebSocket/WebSocketComponent';
import MessageCode from '../MessageCode';
import ObjectControllerCode from '../ObjectControllerCode';
import OrbitCameraComponent from '../OrbitCameraComponent';
import GameObjectComponent from '@runtime/UnityEngineBridge/GameObjectComponent';
import HomeContent from '../HomeContent';
const router = useRouter()

const state = reactive({
    current: 1,
});
function OPQR() {
    HomeContent.Default.QRType.value = true
}
function VLQR() {
    HomeContent.Default.ModuleType.value = 2
    HomeContent.Default.VideoList.value = true
}
async function ret() {
    HomeContent.Default.engine.value = false
    HomeContent.Default.lamplight.value = false
    HomeContent.Default.bigBox.value = true
    WebSocketComponent.Default.PostMessage(new ClientMessage.DiagnosisAdapterMessage(MessageCode.Default.MsgCodesList.SYSTEM_RESET))
    //隐藏模型
    await GameObjectComponent.Default.ShowHideAsync(HomeContent.Default.ModelID.value[0], false);
    await GameObjectComponent.Default.HideAsync(HomeContent.Default.ModelID.value[2]);
    //重置
    await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.DiagnosisAdapterRequest(MessageCode.Default.MsgCodesList.SYSTEM_RESET))
    HomeContent.Default.VideoList.value = false
    router.push('/')

}
function SelectModule(index: number) {
    state.current = index
}
function ArrowClick() {
    let newArr = { Id: 0, Content: 'Press' }
    let RelenewArr = { Id: 0, Content: 'Release' }
    if (state.current == 1) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LFU
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LFD
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    } else if (state.current == 2) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LBU
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LBD
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    } else if (state.current == 4) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RFU
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RFD
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    } else if (state.current == 5) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RBU
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RBD
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    }
}
function ArrowRelease() {
    let newArr = { Id: 0, Content: 'Release' }
    if (state.current == 1) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LFU
        MessageMethod(newArr)
    } else if (state.current == 2) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LBU
        MessageMethod(newArr)
    } else if (state.current == 4) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RFU
        MessageMethod(newArr)
    } else if (state.current == 5) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RBU
        MessageMethod(newArr)
    }
}
function DowArrowClick() {
    let newArr = { Id: 0, Content: 'Press' }
    let RelenewArr = { Id: 0, Content: 'Release' }
    if (state.current == 1) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LFD
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LFU
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    } else if (state.current == 2) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LBD
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LBU
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    } else if (state.current == 4) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RFD
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RFU
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    } else if (state.current == 5) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RBD
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RBU
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    }
}
function DowArrowRelease() {
    let newArr = { Id: 0, Content: 'Release' }
    if (state.current == 1) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LFD
        MessageMethod(newArr)
    } else if (state.current == 2) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LBD
        MessageMethod(newArr)
    } else if (state.current == 4) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RFD
        MessageMethod(newArr)
    } else if (state.current == 5) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RBD
        MessageMethod(newArr)
    }
}
//一键开启
function OpenDirectly() {
    let newArr = { Id: 0, Content: '' }
    let RelenewArr = { Id: 0, Content: 'Release' }
    if (state.current == 1) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LFD
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LFU
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    } else if (state.current == 2) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LBD
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LBU
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    } else if (state.current == 4) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RFD
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RFU
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    } else if (state.current == 5) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RBD
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RBU
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    }
}
//一键关闭
function DirectlyClose() {
    let newArr = { Id: 0, Content: '' }
    let RelenewArr = { Id: 0, Content: 'Release' }
    if (state.current == 1) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LFU
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LFD
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    } else if (state.current == 2) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LBU
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_LBD
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    } else if (state.current == 4) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RFU
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RFD
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    } else if (state.current == 5) {
        newArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RBU
        RelenewArr.Id = ObjectControllerCode.Default.MsgCodesList.WINDOW_MAIN_RBD
        ReleaseResources(RelenewArr)
        MessageMethod(newArr)
    }
}
//释放资源
function ReleaseResources(Arr: any) {
    WebSocketComponent.Default.PostMessage(new ClientMessage.DiagnosisAdapterMessage(MessageCode.Default.MsgCodesList.DISASSEMBLY_OBJECT_VEHICLE_CONTROLLER, JSON.stringify(Arr)))
}

function MessageMethod(Arr: any) {
    WebSocketComponent.Default.PostMessage(new ClientMessage.DiagnosisAdapterMessage(MessageCode.Default.MsgCodesList.DISASSEMBLY_OBJECT_VEHICLE_CONTROLLER, JSON.stringify(Arr)))
}
onMounted(async () => {
    let newArr: any = await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.DiagnosisAdapterRequest(MessageCode.Default.MsgCodesList.VIEW_DATA_CONFIG, `2`))
    console.log(JSON.parse(newArr.Content).Result);
    let ValData = JSON.parse(newArr.Content).Result
    await OrbitCameraComponent.Default.UpdateV2Async(ValData.TargetContainer, ValData.Horizontal, ValData.Vertical, ValData.Distance, ValData.MinDistance, ValData.MaxDistance, ValData.VerticalAngleMax, ValData.VerticalAngleMin, 1, 1, 1, ValData.HorizontalAngleMax, ValData.HorizontalAngleMin);
})
</script>

<style scoped>
.ws_wp {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    position: relative;
    color: #fff;
    background: transparent;
    /* background: #000; */
}

.return_ico {
    width: 50px;
    position: absolute;
    left: 10px;
    top: 10px;
}

.ActionBar {
    width: 1091px;
    height: 181px;
    background-image: url('/images/Benz600/control_window_bg.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    position: absolute;
    bottom: 34px;
    left: 435px;
}

.fb_l {
    width: 89px;
    height: 97px;
    background-image: url('/images/Benz600/btn_play.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    position: absolute;
    left: 24px;
    transition: all 0.1s linear;
    top: 35px;
}

.fb_l:hover {
    transform: scale(1.05);
    transition: all 0.1s linear;
}

.fb_r {
    width: 119px;
    height: 132px;
    background-image: url('/images/Benz600/btn_QRcode.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    position: absolute;
    top: 17px;
    right: 34px;
    transition: all 0.1s linear;
}

.fb_r:hover {
    transform: scale(1.05);
    transition: all 0.1s linear;
}

.upArrow {
    width: 74px;
    height: 74px;
    background-image: url('/images/Benz600/up_normal.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    position: absolute;
    left: 443px;
    top: 55px;
}

.upArrow:hover {
    background-image: url('/images/Benz600/up.png');
}

.downArrow {
    width: 74px;
    height: 74px;
    background-image: url('/images/Benz600/down_normal.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    position: absolute;
    left: 523px;
    top: 55px;
}

.downArrow:hover {
    background-image: url('/images/Benz600/down.png');
}

.upArrow2 {
    width: 74px;
    height: 74px;
    background-image: url('/images/Benz600/down2_normal.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    position: absolute;
    left: 603px;
    top: 55px;
}

.upArrow2:hover {
    background-image: url('/images/Benz600/down2.png');
}

.downArrow2 {
    width: 74px;
    height: 74px;
    background-image: url('/images/Benz600/up2_normal.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    position: absolute;
    left: 363px;
    top: 55px;
}

.downArrow2:hover {
    background-image: url('/images/Benz600/up2_2.png');
}

.locw {
    width: 140px;
    height: 24px;
    background-image: url('/images/Benz600/normal_bg.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    position: absolute;
    left: 135px;
    top: 8px;
    text-align: center;
    line-height: 24px;
    font-size: 14px;
}

.locw:hover {
    background-image: url('/images/Benz600/select_bg.png');
    transform: scale(1.1);
    transition: all 0.1s linear;
}

.locwSele {
    background-image: url('/images/Benz600/select_bg.png');
    transform: scale(1.1);
}

.L2 {
    left: 290px;
}

.L3 {
    left: 445px;
}

.L4 {
    left: 600px;
}

.L5 {
    left: 754px;
}
</style>